/*
 * Copyright 2015 Hongxin Telecommunication Technologies Co, Ltd.,
 * Wuhan, Hubei, China. All rights reserved.
 */
package com.hxrd.job;

import com.hxrd.collect.CmdCollect;
import com.hxrd.data.Device;
import com.hxrd.util.SnmpUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

/**
 *
 * @author chenwei Created on 2016-12-26, 18:27:10
 */
public class AcPollJob implements Job
{

	private static Log log = LogFactory.getLog(AcPollJob.class);

	public void execute(JobExecutionContext context)
			throws JobExecutionException
	{
		String obj = null;
		long currentTime = System.currentTimeMillis();
		Device dev = (Device)context.getMergedJobDataMap().get("device");
		try
		{
			//if ok return, else go to start snmp process
			obj = SnmpUtil.
					snmpGet(dev.getIp(), dev.getCommunity(), dev.getPort(), dev.getVersion(), "1.3.6.1.2.1.1.3.0");
		}
		catch(Exception ex)
		{
			log.info("error:"+dev.getIp());
		}
		if(obj != null)
		{
			return;
		}
		CmdCollect collect = new CmdCollect();
		if(!collect.shellCommand(dev))
		{
			log.info("device "+dev.getIp()+" execute failed, it cast time:"+(System.currentTimeMillis()-currentTime)+"ms");
		}
	}

}
